package com.fit2cloud.common.provider.impl.openstack;

import com.fit2cloud.common.platform.credential.Credential;
import com.fit2cloud.common.platform.credential.impl.OpenStackCredential;
import com.fit2cloud.common.provider.AbstractBaseCloudProvider;
import com.fit2cloud.common.provider.entity.F2CBalance;
import com.fit2cloud.common.provider.impl.openstack.api.OpenStackBaseMethodApi;
import com.fit2cloud.common.provider.impl.openstack.entity.Zone;
import com.fit2cloud.common.provider.impl.openstack.entity.request.OpenStackBaseRequest;
import com.fit2cloud.common.utils.JsonUtil;
import org.pf4j.Extension;

import java.util.List;
import java.util.Map;


@Extension
public class OpenStackBaseCloudProvider extends AbstractBaseCloudProvider<OpenStackCredential> {
    private static final String logoSvg = "<svg width=\"160\" height=\"38\" viewBox=\"0 0 160 38\" fill=\"none\" xmlns=\"http://www.w3.org/2000/svg\">\n" +
            "<path d=\"M28.6459 5H6.01157C4.591 5 3.42871 6.16229 3.42871 7.58286V13.6697H9.70643V12.6754C9.70643 11.904 10.3316 11.2789 11.103 11.2789H23.5544C24.3259 11.2789 24.951 11.904 24.951 12.6754V13.6697H31.2287V7.584C31.2287 6.16229 30.0664 5 28.6459 5Z\" fill=\"#DA1A32\"/>\n" +
            "<path d=\"M24.951 24.5337C24.951 25.3051 24.3259 25.9303 23.5544 25.9303H11.1041C10.3327 25.9303 9.70757 25.3051 9.70757 24.5337V23.5394H3.42871V29.6263C3.42871 31.0469 4.591 32.2091 6.01157 32.2091H28.6459C30.0664 32.2091 31.2287 31.0469 31.2287 29.6263V23.5394H24.951V24.5337Z\" fill=\"#DA1A32\"/>\n" +
            "<path d=\"M9.70642 15.4651H3.42871V21.7428H9.70642V15.4651Z\" fill=\"#DA1A32\"/>\n" +
            "<path d=\"M31.2289 15.4651H24.9512V21.7428H31.2289V15.4651Z\" fill=\"#DA1A32\"/>\n" +
            "<path d=\"M156.571 23.8778C156.571 22.9041 155.779 22.1121 154.806 22.1121C153.832 22.1121 153.04 22.9041 153.04 23.8778C153.04 24.8515 153.832 25.6435 154.806 25.6435C155.779 25.6435 156.571 24.8515 156.571 23.8778ZM154.806 25.2103C154.071 25.2103 153.473 24.6126 153.473 23.8778C153.473 23.1429 154.071 22.5452 154.806 22.5452C155.541 22.5452 156.138 23.1429 156.138 23.8778C156.137 24.6126 155.539 25.2103 154.806 25.2103Z\" fill=\"#4E4540\"/>\n" +
            "<path d=\"M155.467 23.5577V23.5474C155.467 23.3772 155.416 23.2412 155.321 23.1463C155.213 23.0377 155.051 22.9806 154.851 22.9806H154.201V24.7109H154.559V24.1429H154.784L155.103 24.7109H155.513L155.145 24.0686C155.337 23.9852 155.467 23.8194 155.467 23.5577ZM155.106 23.568C155.106 23.7234 155.007 23.8274 154.824 23.8274H154.56V23.3052H154.817C155 23.3052 155.106 23.392 155.106 23.5646V23.568Z\" fill=\"#4E4540\"/>\n" +
            "<path d=\"M50.4951 18.7245V18.4845C50.4951 14.3063 47.7545 11.272 44.0288 11.272C40.2756 11.272 37.5088 14.3588 37.5088 18.5108V18.7497C37.5088 22.928 40.2505 25.9348 43.9762 25.9348C47.7271 25.936 50.4951 22.8765 50.4951 18.7245ZM40.5145 18.6708V18.5108C40.5145 15.8754 41.8722 13.9337 43.9739 13.9337C46.0231 13.9337 47.4871 15.9028 47.4871 18.5371V18.6971C47.4871 21.3314 46.1294 23.3005 44.0276 23.3005C41.9785 23.3017 40.5145 21.3063 40.5145 18.6708Z\" fill=\"#4E4540\"/>\n" +
            "<path d=\"M64.81 18.7783V18.4058C64.81 13.6412 62.1483 11.2732 59.3277 11.2732C57.3049 11.2732 56.0809 12.4446 55.2031 13.8012V11.5383H52.1963V29.6618H55.2031V23.5143C56.0546 24.7646 57.2786 25.9098 59.3277 25.9098C62.1757 25.9098 64.81 23.5155 64.81 18.7783ZM55.1494 18.7246V18.4583C55.1494 15.6903 56.6934 13.9349 58.5026 13.9349C60.3129 13.9349 61.7757 15.6652 61.7757 18.4858V18.7258C61.7757 21.5475 60.3391 23.2503 58.5026 23.2503C56.6934 23.2492 55.1494 21.4926 55.1494 18.7246Z\" fill=\"#4E4540\"/>\n" +
            "<path d=\"M77.8411 23.7543L76.2708 21.8915C75.3393 22.7966 74.3542 23.3818 73.0239 23.3818C71.1873 23.3818 69.7233 22.104 69.4582 19.736H78.2936C78.3199 19.3109 78.3199 18.8846 78.3199 18.6983C78.3199 14.4675 76.2971 11.2732 72.4651 11.2732C69.0056 11.2732 66.4502 14.3075 66.4502 18.5383V18.7509C66.4502 23.1692 69.2708 25.9361 72.8902 25.9361C74.9931 25.9361 76.5633 25.1121 77.8411 23.7543ZM72.4651 13.8012C74.2216 13.8012 75.2331 15.4241 75.3931 17.6595H69.4319C69.6445 15.2652 70.8148 13.8012 72.4651 13.8012Z\" fill=\"#4E4540\"/>\n" +
            "<path d=\"M87.1514 11.2732C85.2349 11.2732 84.0909 12.3646 83.292 13.6149V11.5395H80.2852V25.6446H83.292V17.1018C83.292 15.1589 84.3834 13.9875 85.9537 13.9875C87.5503 13.9875 88.4817 15.0789 88.4817 17.0481V25.6446H91.4886V16.1966C91.4886 13.1886 89.8657 11.2732 87.1514 11.2732Z\" fill=\"#4E4540\"/>\n" +
            "<path d=\"M103.61 21.6251V21.5988C103.61 19.3897 101.96 18.3794 99.778 17.3943C98.1278 16.6491 97.01 16.1703 97.01 15.2388V15.1851C97.01 14.4137 97.6752 13.8011 98.7929 13.8011C99.9106 13.8011 101.082 14.3337 102.146 15.0514L103.424 12.8423C102.093 11.8845 100.417 11.3257 98.8466 11.3257C96.2123 11.3257 94.1895 12.9223 94.1895 15.4503V15.504C94.1895 17.8194 95.946 18.7771 98.0489 19.6823C99.7255 20.4011 100.817 20.8537 100.817 21.8651V21.8914C100.817 22.7703 100.098 23.4354 98.8478 23.4354C97.5975 23.4354 96.2398 22.8228 94.962 21.7863L93.5518 23.9417C95.1758 25.2983 97.1175 25.9108 98.794 25.9108C101.508 25.9097 103.61 24.3931 103.61 21.6251Z\" fill=\"#4E4540\"/>\n" +
            "<path d=\"M112.923 25.2446V22.7692C112.418 23.0354 111.885 23.168 111.299 23.168C110.341 23.168 109.782 22.7154 109.782 21.624V14.1189H112.949V11.5372H109.782V7.73145H106.775V11.5372H105.231L105.725 14.1189H106.774V22.2354C106.774 24.9772 108.345 25.8549 110.42 25.8549C111.433 25.8572 112.231 25.6172 112.923 25.2446Z\" fill=\"#4E4540\"/>\n" +
            "<path d=\"M124.446 12.816C123.54 11.8845 122.13 11.3794 120.294 11.3794C118.404 11.3794 116.993 11.832 115.636 12.4971L116.488 14.8925C117.419 14.4674 118.537 14.0411 119.895 14.0411C121.811 14.0411 122.929 15.0263 122.929 16.9154V17.5017C121.971 17.1817 121.012 16.9428 119.682 16.9428C116.702 16.9428 114.679 18.4331 114.679 21.4663V21.5988C114.679 24.3405 116.648 25.9097 118.99 25.9097C120.826 25.9097 122.076 25.1108 122.902 23.9143V25.6445H125.856V16.8891C125.856 15.1314 125.377 13.7474 124.446 12.816ZM122.955 20.9063C122.955 22.5028 121.625 23.6743 119.895 23.648C118.591 23.6217 117.607 22.8228 117.607 21.4125V21.3588C117.607 19.8685 118.618 18.9908 120.347 18.9908C121.359 18.9908 122.264 19.2034 122.955 19.496V20.9063Z\" fill=\"#4E4540\"/>\n" +
            "<path d=\"M138.639 23.8081L137.016 21.8126C136.191 22.6378 135.366 23.2492 134.142 23.2492C132.093 23.2492 130.656 21.4126 130.656 18.6721V18.5395C130.656 15.8778 132.093 13.9886 134.063 13.9886C135.341 13.9886 136.166 14.6275 136.911 15.3989L138.588 13.1898C137.416 12.0183 136.086 11.2732 134.063 11.2732C130.364 11.2732 127.623 14.3075 127.623 18.5121V18.7783C127.623 22.9829 130.285 25.9372 133.957 25.9372C136.111 25.9361 137.521 25.0583 138.639 23.8081Z\" fill=\"#4E4540\"/>\n" +
            "<path d=\"M147.844 18.3234L145.733 20.5919L148.564 25.6434H152.051L147.844 18.3234Z\" fill=\"#4E4540\"/>\n" +
            "<path d=\"M148.351 11.5383L143.534 17.7394V6.42969H140.527V25.6434H143.534V21.5725L151.918 11.5383H148.351Z\" fill=\"#4E4540\"/>\n" +
            "</svg>\n";

    private static final String iconSvg = "<svg t=\"1688522358260\" class=\"icon\" viewBox=\"0 0 1024 1024\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" p-id=\"13769\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"100%\" height=\"100%\"><path d=\"M768 384h192v256h-192zM64 384h192v256H64zM768 704v64H256v-64H64v188.8A67.2 67.2 0 0 0 131.2 960h761.6a67.2 67.2 0 0 0 67.2-67.2V704h-192zM256 320V256h512v64h192V131.2A67.2 67.2 0 0 0 892.8 64H131.2A67.2 67.2 0 0 0 64 131.2V320h192z\" fill=\"#d21f33\" p-id=\"13770\"></path></svg>";

    private static final CloudAccountMeta cloudAccountMeta = new CloudAccountMeta(OpenStackCredential.class, "fit2cloud_openstack_platform", "OpenStack", false, logoSvg, iconSvg, Map.of());
    private static final Info info = new Info("management-center", List.of(), Map.of());

    @Override
    public F2CBalance getAccountBalance(String req) {
        return null;
    }

    @Override
    public CloudAccountMeta getCloudAccountMeta() {
        return cloudAccountMeta;
    }

    @Override
    public Info getInfo() {
        return info;
    }

    public List<Credential.Region> getRegions(String req) {
        return OpenStackBaseMethodApi.getRegions(JsonUtil.parseObject(req, OpenStackBaseRequest.class));
    }

    public static List<Zone> getZones(String req) {
        return OpenStackBaseMethodApi.getZones(JsonUtil.parseObject(req, OpenStackBaseRequest.class));
    }

}
